package com.yinhai.chat;

import com.yinhai.activity.R;




public class Expressions {

	public static int[] expressionImgs = new int[] { R.drawable.f000,
			R.drawable.f001, R.drawable.f002, R.drawable.f003, R.drawable.f004,
			R.drawable.f005, R.drawable.f006, R.drawable.f007, R.drawable.f008,
			R.drawable.f009, R.drawable.f010, R.drawable.f011, R.drawable.f012,
			R.drawable.f013, R.drawable.f014, R.drawable.f015, R.drawable.f016,
			R.drawable.f017, R.drawable.f018, R.drawable.f019, R.drawable.f020,
			R.drawable.f021, R.drawable.f022, R.drawable.f023 };

	/**
	 * 本地表情的名字
	 */
	public static String[] expressionImgNames = new String[] { "[f000]",
			"[f001]", "[f002]", "[f003]", "[f004]", "[f005]", "[f006]",
			"[f007]", "[f008]", "[f009]", "[f010]", "[f011]", "[f012]",
			"[f013]", "[f014]", "[f015]", "[f016]", "[f017]", "[f018]",
			"[f019]", "[f020]", "[f021]", "[f022]", "[f023]" };
	
	
	
	public static int[] expressionImgs1 = new int[] { R.drawable.f024,
		R.drawable.f025, R.drawable.f026, R.drawable.f027, R.drawable.f028,
		R.drawable.f029, R.drawable.f030, R.drawable.f031, R.drawable.f032,
		R.drawable.f033, R.drawable.f034, R.drawable.f035, R.drawable.f036,
		R.drawable.f037, R.drawable.f038, R.drawable.f039, R.drawable.f040,
		R.drawable.f041, R.drawable.f042, R.drawable.f043, R.drawable.f044,
		R.drawable.f045, R.drawable.f046, R.drawable.f047 };
	
	/**
	 * 本地表情的名字
	 */
	public static String[] expressionImgNames1 = new String[] { "[f024]",
		"[f025]", "[f026]", "[f027]", "[f028]", "[f029]", "[f030]",
		"[f031]", "[f032]", "[f033]", "[f034]", "[f035]", "[f036]",
		"[f037]", "[f038]", "[f039]", "[f040]", "[f041]", "[f042]",
		"[f043]", "[f044]", "[f045]", "[f046]", "[f047]" };
	
	
	
	
	public static int[] expressionImgs2 = new int[] { R.drawable.f048,
		R.drawable.f049, R.drawable.f050, R.drawable.f051, R.drawable.f052,
		R.drawable.f053, R.drawable.f054, R.drawable.f055, R.drawable.f056,
		R.drawable.f057, R.drawable.f058, R.drawable.f059, R.drawable.f060,
		R.drawable.f061, R.drawable.f062, R.drawable.f063, R.drawable.f064,
		R.drawable.f065, R.drawable.f066, R.drawable.f067, R.drawable.f068,
		R.drawable.f069, R.drawable.f070, R.drawable.f071 };
	
	/**
	 * 本地表情的名字
	 */
	public static String[] expressionImgNames2 = new String[] { "[f048]",
		"[f049]", "[f050]", "[f051]", "[f052]", "[f053]", "[f054]",
		"[f055]", "[f056]", "[f057]", "[f058]", "[f059]", "[f060]",
		"[f061]", "[f062]", "[f063]", "[f064]", "[f065]", "[f066]",
		"[f067]", "[f068]", "[f069]", "[f070]", "[f071]" };

	
	private final static String[] FACEKEYS = {"f000","f001","f002","f003","f004","f005","f006","f007","f008","f009","f010","f011","f012","f013","f014","f015","f016","f017","f018","f019","f020","f021","f022","f023","f024","f025","f026","f027","f028","f029","f030","f031","f032","f033","f034","f035","f036","f037","f038","f039","f040","f041","f042","f043","f044","f045","f046","f047","f048","f049","f050","f051","f052","f053","f054","f055","f056","f057","f058","f059","f060","f061","f062","f063","f064","f065","f066","f067","f068","f069","f070","f071"};
	private final static char FACE_BEGIN_CHAR = 'f';
	private final static char FACE_PREFIX = '[';
	private final static char FACE_SUFFIX = ']';
	private final static int FACE_CODE_LEN = 4;
	
	/**
	 * 
	 * 
	 * 
	 */
	/*
	 * 服务器存储的表情名字
	 */
	public static String[] expressionRegImgNames = new String[] { "\\U0001F601",
			"f0asd01", "f00asd2", "fasd003", "f0gf04", "f00fg5", "f0gfdh06",
			"fhjgh007", "f0gh08", "ffgh009", "f010", "f011", "f012", "f013",
			"f014", "f015", "f016", "f017", "f05err18", "f045fd19",
			"f0234sdf20", "fsdfg021", "f0jjjh22", "f0hjh23" };

	/**
	 * 
	 * 在存入数据库时，将表情名字进行替换即
	 * 
	 */
	public static String[] replaceStrings(String[] str, String[] str2) {
		String newStr[] = new String[str.length - 1];
		for (int i = 0; i < str.length; i++) {
			newStr[i] = str[i].replace(str[i], str2[i]);
		}
		return newStr;
	}
	
	
	public static String ReceiveTxtMsgTranslate(String src) {
		int m = 0, n = 0, pos = 0, i = 0;
		StringBuffer buf = new StringBuffer();
		while(true) {
			m = src.indexOf(FACE_PREFIX, pos);
			if(m == -1) {
				buf.append(src.substring(pos));
				break;
			}
			n = src.indexOf(FACE_SUFFIX, m);
			if(n == -1) {
				buf.append(src.substring(pos));
				break;
			}
			buf.append(src.substring(pos, m));
			if(n - m != FACE_CODE_LEN + 1) {
				buf.append(FACE_PREFIX);
				pos = m + 1;
			} else {
				String tmp = src.substring(m + 1, n);
				for(i = 0; i < FACEKEYS.length; ++i) {
					if(tmp.equals(FACEKEYS[i])) {
						break;
					}
				}
				if(i < FACEKEYS.length) {
					buf.append(tmp);
					pos = n + 1;
				} else {
					buf.append(src.substring(m, n + 1));
					pos = n + 1;
				}
			}
		}
		return buf.toString();
	}
	
	public static String SendTxtMsgTranslate(String src) {
		int m = 0, n = 0, i = 0;
		StringBuffer buf = new StringBuffer();
		int size = src.length();
		if(size < FACE_CODE_LEN) {
			buf.append(src);
			return buf.toString();
		}
		
		while(true) {
			m = src.indexOf(FACE_BEGIN_CHAR, n);
			if(m == -1 || m > size - FACE_CODE_LEN) {
				buf.append(src.substring(n));
				break;
			}
			String tmp = src.substring(m, m + FACE_CODE_LEN);
			for(i = 0; i < FACEKEYS.length; ++i) {
				if(tmp.equals(FACEKEYS[i])) {
					break;
				}
			}
			if(i < FACEKEYS.length) {
				buf.append(src.substring(n, m));
				buf.append(FACE_PREFIX);
				buf.append(tmp);
				buf.append(FACE_SUFFIX);
				n = m + FACE_CODE_LEN;
			} else {
				buf.append(src.substring(n, m + 1));
				n = m + 1;
			}
		}
		return buf.toString();
	}

}
